package com.csgc.camera.util

import com.csgc.camera.application.CameraApplication
import com.csgc.camera.constants.Constants
import com.hjq.toast.ToastUtils
import com.hlyj.http.base.tool.lib_hlyj_base.BaseApplication
import com.tencent.mm.opensdk.modelmsg.SendAuth
import com.tencent.mm.opensdk.modelmsg.WXImageObject
import com.tencent.mm.opensdk.modelpay.PayReq
import com.tencent.mm.opensdk.openapi.IWXAPI
import com.tencent.mm.opensdk.openapi.WXAPIFactory

class WXWrapper private constructor() {
    companion object {
        val instance: WXWrapper by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            WXWrapper()
        }
    }

    val wxApi:IWXAPI = WXAPIFactory.createWXAPI(BaseApplication.instance,"wx186c2850a6a09b41",true)
    init {
        wxApi.registerApp("wx186c2850a6a09b41")
    }


    fun login(){
        if (wxApi.isWXAppInstalled){
            val req = SendAuth.Req()
            req.scope = "snsapi_userinfo"
            req.state = Constants.WXAuthType.LOGIN.state
            wxApi.sendReq(req)
        }else{
            ToastUtils.show("您尚未安装微信")
        }
    }

    fun bind(){
        if (wxApi.isWXAppInstalled){
            val req = SendAuth.Req()
            req.scope = "snsapi_userinfo"
            req.state = Constants.WXAuthType.BIND.state
            wxApi.sendReq(req)
        }else{
            ToastUtils.show("您尚未安装微信")
        }
    }

    fun pay(req: PayReq){
        wxApi.sendReq(req)
    }

}

